package api

import (
	"context"
	"gitee.com/kristas/booting-go/framework"
	"gitee.com/kristas/booting-go/framework/core/statement/types"
	"gitee.com/kristas/booting-go/framework/web/resp"
	"gitee.com/kristas/booting-go/framework/web/rest"
	"gitee.com/kristas/booting-go/internal/demo/dto"
	"gitee.com/kristas/booting-go/internal/demo/feign"
)

func init() {
	framework.Component(new(FeignController))
}

type FeignController struct {
	types.Controller `group:"/feign"`
	feign.Factory    `wire:"feign_factory"`
	testGetAllUsers  rest.GET  `url:"/users"`
	getUserById      rest.GET  `url:"/{username}" param:"[c context,username path]"`
	saveUser         rest.POST `url:"/{username}/save" param:"[c context,username path,user body]"`
}

func (h *FeignController) TestGetAllUsers() ([]*dto.AccountDTO, error) {
	return h.GetTestClient().FindAllUsers()
}

func (h *FeignController) GetUserById(ctx context.Context, username string) (*dto.AccountDTO, error) {
	return h.GetTestClient().GetUserById(ctx, username)
}

func (h *FeignController) SaveUser(ctx context.Context, username string, employee *dto.AccountDTO) (resp.Response, error) {
	return h.GetTestClient().SaveUser(ctx, username, employee)
}
